import java.net.*;
import java.io.*;

public class Server
{
	public static void main(String args[])
	{
		ServerSocket serverSocket = null;
		Socket socket = null;
		InputStream inp = null;
		BufferedReader brinp = null;
		DataOutputStream out = null;
		try{
			serverSocket = new ServerSocket(6666);
		}
		catch(IOException e){
			System.out.println("Bd przy tworzeniu gniazda serwerowego.");
			System.exit(-1);
		}
		try{
			socket = serverSocket.accept();
		}
		catch(IOException e){
			System.out.println(e);
		}
		try{
			inp = socket.getInputStream();
			brinp = new BufferedReader(new InputStreamReader(inp));
			out = new DataOutputStream(socket.getOutputStream());
		}
		catch(IOException e){
			System.out.println("Bd przy tworzeniu strumieni.");
			System.exit(-1);
		}
		String line;
		while(true){
			try{
				line = brinp.readLine();
				if(line.equals("quit")){
					try{
						serverSocket.close();
					}
					catch(IOException e){
System.out.println("Bd przy zamykaniu gniazda serwerowego");
					}
				System.exit(0);
				}
				out.writeBytes(line + "\n\r");
			}
			catch(IOException e){
				System.out.println("Bd wejcia-wyjcia.");
				System.exit(-1);
			}
		}
	}
}
